package lab3.io;

import config.Config;

import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 * Created by Student on 17.12.2014.
 */
public class ClientThroughputIO {

    public static final double TESTING_TIME = 30;

    /**
     * When client connected to server,
     * Server send objects to client.
     * Client calculate number of getting objects per second
     *
     * @param args
     */
    public static void main(String[] args) {
        try (Socket s = new Socket(Config.ADDRESS, Config.PORT);) {
            ObjectInputStream ois = new ObjectInputStream(s.getInputStream());

            long start = System.currentTimeMillis();
            long end = System.currentTimeMillis();
            int counter = 0;

            while ((end - start) < 1000 * TESTING_TIME) {
                ois.readObject();
                end = System.currentTimeMillis();
                counter++;
            }
            System.out.println(counter / TESTING_TIME);

        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
